
#include "common.h"

#define BUFF_MAX (1024)
u8 recv_buff[BUFF_MAX];

int main(int argc, char **argv)
{
	int sock_fd = get_sock("127.0.0.1",PORT);
	sock_fd = get_connfd(sock_fd);
	fd_set readmask;
	fd_set fdset;
	FD_ZERO(&fdset);
	//socketfd放到select监听
	FD_SET(sock_fd, &fdset);

	while(1){
		readmask = fdset;
		int n = select(sock_fd+1,&readmask,NULL,NULL,NULL);
		if(n < 0){
			error(1, errno, "select failed!");
		}

	    if(FD_ISSET(sock_fd, &readmask))
	    {
	        n = read(sock_fd, recv_buff, BUFF_MAX);
	        if(n < 0){
	            error(1, errno, "read error!");
	        } 

	        recv_buff[n] = '\0';	        
	        printf("recv:%s\n", recv_buff);	     
	        n = write(sock_fd,"server recv done.\n",strlen("server recv done.\n"));   
	        if(n < 0){
	            error(1, errno, "write error!");
	        } 	        
        }
	}
	return 0;
}